package com.zhiwei.gateway.route;

import org.springframework.cloud.netflix.zuul.filters.RefreshableRouteLocator;
import org.springframework.cloud.netflix.zuul.filters.SimpleRouteLocator;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;

import java.util.HashMap;
import java.util.Map;

import static org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute;

/**
 * function: zuul动态路由
 * author: zhiwei_yang
 * time: 2020/2/10-13:17
 */
public class ZuulSimpleRouteLocator extends SimpleRouteLocator implements RefreshableRouteLocator {

    public ZuulSimpleRouteLocator(String servletPath, ZuulProperties properties) {
        super(servletPath, properties);
    }

    @Override
    protected Map<String, ZuulRoute> locateRoutes() {
        Map<String, ZuulProperties.ZuulRoute> routesMap = new HashMap<>(super.locateRoutes());
        String path = "/project/**";
        ZuulRoute zuulRoute = new ZuulRoute();
        zuulRoute.setId(path);
        zuulRoute.setPath(path);
        zuulRoute.setServiceId("publish-project");
        zuulRoute.setStripPrefix(true);
        routesMap.put(path, zuulRoute);
        return routesMap;
    }

    @Override
    public void refresh() {
        super.doRefresh();
    }
}